package com.oa.ylms.apps.business.archives.impl;

import java.util.List;

import com.oa.ylms.apps.business.archives.IArchiveInfoService;
import com.oa.ylms.apps.business.archives.IRPCategoryService;
import com.oa.ylms.apps.business.archives.IRPInfoService;
import com.oa.ylms.apps.common.DateUtil;
import com.oa.ylms.apps.dao.archives.IRPInfoDao;
import com.oa.ylms.apps.entity.archives.RPCategoryValue;
import com.oa.ylms.apps.entity.archives.RPInfoValue;

public class RPInfoServiceImpl implements IRPInfoService {
	private IRPCategoryService rpCategoryService;
	private IArchiveInfoService archiveInfoService;
	private RPInfoValue rpInfo;
	private RPCategoryValue rpCategory;
	private IRPInfoDao infoDao;

	@Override
	public int addRPInfo(int categoryId,String createTime, int archiveId, String contents)
			throws Exception {
		rpInfo.setArchiveInfo(archiveInfoService.queryByArchiveId(archiveId));
		rpInfo.setRpCategory(rpCategoryService.queryByCategoryId(categoryId));
		if(rpInfo.getArchiveInfo() != null && rpInfo.getRpCategory() != null){
			rpInfo.setContents(contents);
			rpInfo.setCreateTime(DateUtil.toDateWithoutHours(createTime));
			return infoDao.addRPInfo(rpInfo);
		}
		return 0;
	}

	@Override
	public boolean deleteRPInfo(int rpId) throws Exception {
		rpInfo = queryByRPId(rpId);
		if(rpInfo != null){
			return infoDao.deleteRPInfo(rpInfo);
		}
		return false;
	}

	@Override
	public boolean modifyRPInfo(int rpId, String contents) throws Exception {
		rpInfo = queryByRPId(rpId);
		if(rpInfo != null){
			rpInfo.setContents(contents);
			return infoDao.modifyRPInfo(rpInfo);
		}
		return false;
	}

	@Override
	public RPInfoValue queryByRPId(int rpId) throws Exception {
		rpInfo.setRpId(rpId);
		return infoDao.queryByRPId(rpInfo);
	}

	@Override
	public List<RPInfoValue> queryRPInfo(Integer categoryId, Integer archiveId, Integer isRP)
			throws Exception {
		if(archiveId != null)
		rpInfo.setArchiveInfo(archiveInfoService.queryByArchiveId(archiveId));
		if(categoryId != null)
		rpInfo.setRpCategory(rpCategoryService.queryByCategoryId(categoryId));
		if(isRP != null)
		rpCategory.setIsRP(isRP);
		return infoDao.queryRPInfo(rpInfo,rpCategory);
	}
	
	public IRPCategoryService getRpCategoryService() {
		return rpCategoryService;
	}

	public void setRpCategoryService(IRPCategoryService rpCategoryService) {
		this.rpCategoryService = rpCategoryService;
	}

	public IArchiveInfoService getArchiveInfoService() {
		return archiveInfoService;
	}

	public void setArchiveInfoService(IArchiveInfoService archiveInfoService) {
		this.archiveInfoService = archiveInfoService;
	}

	public RPInfoValue getRpInfo() {
		return rpInfo;
	}

	public void setRpInfo(RPInfoValue rpInfo) {
		this.rpInfo = rpInfo;
	}

	public IRPInfoDao getInfoDao() {
		return infoDao;
	}

	public void setInfoDao(IRPInfoDao infoDao) {
		this.infoDao = infoDao;
	}

	public void setRpCategory(RPCategoryValue rpCategory) {
		this.rpCategory = rpCategory;
	}

	public RPCategoryValue getRpCategory() {
		return rpCategory;
	}

}
